<template>
  <div>
    <el-dropdown trigger="click">
      <div>
        <el-tooltip effect="dark" content="主题模式">
          <el-icon :size="20">
            <MagicStick />
          </el-icon>
        </el-tooltip>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item v-for="(theme, index) in themeList" :key="index" :disabled="activeThemeName === theme.name"
            @click="(e: MouseEvent) => handleChangeTheme(e, theme.name)">
            <span>{{ theme.title }}</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useTheme } from '@/utils/useTheme'
import { type ThemeName } from '@/utils/useTheme'
const { themeList, activeThemeName, setTheme } = useTheme()

function handleChangeTheme({ clientX, clientY }: MouseEvent, themeName: ThemeName) {
  // let maxRadius = Math.hypot(
  //   Math.max(clientX, window.innerWidth - clientX),
  //   Math.max(clientY, window.innerHeight - clientY)
  // )
  // const style = document.documentElement.style
  // style.setProperty("--theme-x", `${clientX}px`)
  // style.setProperty("--theme-y", `${clientY}px`)
  // style.setProperty("--theme-r", `${maxRadius}px`)

  if (document.startViewTransition) {
      document.startViewTransition(() => {
      setTheme(themeName)
    })
  } else {
    setTheme(themeName)
  }
}
</script>

<style scoped></style>
